<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vue开发的收银系统 - 水果店</title>
  </head>
  <body>
    <div id="app">
      <h2>欢迎光临 Vue 开发的收银系统 - 水果店</h2>
      <p><strong>苹果 10元/斤，折扣 &lt; 8折 &gt;</strong></p>
      <label for="quantity">请输入你要购买的斤数:</label>
      <input type="number" id="quantity" v-model.number="quantity" />
      <button @click="buy()">结账买单~</button>
      <p>
        结账单: 总价:{{total}} 元 折后价:{{discount}} 元 省了:
        {{discountPrice}}元
      </p>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          quantity: 0,
          total: 0,
          discount: 0,
          discountPrice: 0,
        },
        computed: {
          total() {
            return this.quantity * 10;
          },
          discount() {
            return this.quantity * 10 * 0.8;
          },
          discountPrice() {
            return this.quantity * 10 * 0.2;
          },
        },
        methods: {
          buy() {
            this.total = this.quantity * 10;
            this.discount = this.quantity * 10 * 0.8;
            this.discountPrice = this.quantity * 10 * 0.2;
          },
        },
      });
    </script>
  </body>
</html>
